package com.woniuxy.controller;

import com.woniuxy.util.OssUtil;
import com.woniuxy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author ：张宇
 * @date ：Created in 2023-03-13 18:53
 * @description：
 * @modified By：
 * @version: $
 */
@RestController
public class fileUpload {
    @Autowired
    private OssUtil ossUtil;//引入工具类

    @PostMapping("/uploadoss")
    public Result fileUpload(@RequestParam("file") MultipartFile file) {
        try {
            String url = ossUtil.uploadFile(file); //调用OSS工具类
            return Result.ok(url);
        } catch (Exception e) {
            return Result.error("上传失败");
        }
    }
}
